package com.nutshare.lt.view;

import com.nutshare.lt.Stat;
import com.nutshare.lt.table.PopularTableModel;
import com.nutshare.lt.table.SelectedTableCellRenderer;

import javax.swing.*;
import javax.swing.table.TableColumn;
import java.awt.*;

public class PopularView extends JPanel
{

    private PopularTableModel model;
    private JTable table;


    public void initCustom(Stat stat)
    {
        model = new PopularTableModel(stat);
        table = new JTable();
        table.setModel(model);

        JScrollPane scrollPane = new JScrollPane(table, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

        table.setFillsViewportHeight(true);
        // table.setPreferredSize(new Dimension(400, 600));
        // table.setPreferredScrollableViewportSize(table.getPreferredSize());
        table.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        scrollPane.setPreferredSize(new Dimension(1000, 780));

        this.add(scrollPane, BorderLayout.CENTER);

        for(int i=0; i<table.getColumnCount(); i++)
        {
            TableColumn c = table.getColumnModel().getColumn(i);
            // c.setPreferredWidth(50);
            c.setMinWidth(50);
            c.setCellRenderer(new SelectedTableCellRenderer());
        }

        this.setSize(720, 620);


    }





}
